<template>
  <div class="demo-info" :class="{ 'is-open': isOpen }">
    <div class="demo-info-toggle" @click="toggleInfo">
      <span v-if="isOpen">−</span>
      <span v-else>ℹ️</span>
    </div>
    <div class="demo-info-content" v-if="isOpen && currentDemoInfo">
      <h3>{{ currentDemoInfo.name }}</h3>
      <p class="demo-description">{{ currentDemoInfo.description }}</p>
      <div class="demo-meta">
        <div class="meta-item">
          <span class="meta-label">Category:</span>
          <span class="meta-value">{{ currentDemoInfo.category }}</span>
        </div>
      </div>
      <div class="demo-actions">
        <el-button @click="showSourceCode" type="primary">
          View Source Code
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { computed, ref } from 'vue';
import demoStore from '../store/demoStore.js';

export default {
  name: 'DemoInfo',
  props: {
    currentDemo: {
      type: String,
      default: 'polygon'
    }
  },
  emits: ['view-source-code'],
  setup(props, { emit }) {
    const isOpen = ref(false);
    
    const currentDemoInfo = computed(() => {
      return demoStore.state.demos.find(demo => demo.id === props.currentDemo);
    });
    
    const toggleInfo = () => {
      isOpen.value = !isOpen.value;
    };
    
    const showSourceCode = () => {
      emit('view-source-code');
    };

    return {
      isOpen,
      currentDemoInfo,
      toggleInfo,
      showSourceCode
    };
  }
};
</script>

<style scoped>
.demo-info {
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border-radius: 50px;
  width: 40px;
  height: 40px;
  transition: all 0.3s ease;
  overflow: hidden;
}

.demo-info.is-open {
  width: auto;
  height: auto;
  border-radius: 5px;
  max-width: 500px;
}

.demo-info-toggle {
  padding: 10px;
  cursor: pointer;
  font-weight: bold;
  text-align: center;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.demo-info.is-open .demo-info-toggle {
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.demo-info-content {
  padding: 15px;
}

.demo-description {
  margin-bottom: 15px;
  line-height: 1.4;
}

.demo-meta {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.meta-item {
  margin-right: 20px;
  margin-bottom: 10px;
}

.meta-label {
  font-weight: bold;
  margin-right: 5px;
}

.meta-value {
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 6px;
  border-radius: 3px;
}

.demo-actions {
  margin-top: 15px;
  text-align: center;
}
</style>